 layui.use('layer', function () {
     var layer = layui.layer;
     //注册
     $('.reg').click(function () {
         layer.open({
             type: 2,
             title: '注册',
             content: ['register.html', 'no'],
             area: ['800px', '500px'],
             maxHeight: 800,
             end:function(){
                 //location.href = '/login.html'
             }
         });
     });

     //数据库的添加
     $('.sub').click(function (e) {
         //阻止表单默认行为
         e.preventDefault();
         //接收表单数据
         let data = $('#myform').serialize();
         $.post('api/reg', data, function (res) {
             if (res.status == 201) {
                  layer.msg('注册成功',{icon:6,time:1000},function(){
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭 
                  })
             }else{
                 layer.msg('注册失败', {
                     icon: 6,
                     time: 3000
                 })
             }
         })

     });


 })